// UserMapper.java
package com.ny.mapper;

import com.ny.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    @Select("select * from user where nickname = #{nickname}")
    public User findNickname(@Param("nickname") String nickname);

    // 添加注册方法
    @Insert("insert into user(username,password,nickname,phone,email,created_time) " +
            "values(#{username},#{password},#{nickname},#{phone},#{email},#{createdTime})")
     int insertUser(User user);

    // 添加根据用户名查询用户的方法
    @Select("SELECT * FROM user WHERE username = #{username}")
    public User findByUsername(@Param("username") String username);
    
    // 根据邮箱查询用户
    @Select("SELECT * FROM user WHERE email = #{email}")
    public User findUserByEmail(@Param("email") String email);
    
    // 根据邮箱更新密码
    @Update("update user set password = #{password} where email = #{email}")
    public int updatePassword(@Param("password") String password, @Param("email") String email);
}